package com.ruoyi.common.number;

import com.ruoyi.common.utils.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * author: 核桃
 * date: 2023/11/23
 **/
public class NotNumberValidator implements ConstraintValidator<NotNumber,String> {

    private static final String PATTERN = "^[0-9]*$";

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        if (StringUtils.isBlank(value)) {
            return false;
        }
        return !containsNumber(value);
    }

    public static boolean containsNumber(String value)
    {
        Pattern pattern = Pattern.compile(PATTERN);
        Matcher matcher = pattern.matcher(value);
        return matcher.matches();
    }
}
